package zuoye.dao;

import java.util.List;

public class ResultDao {

	// 增加一个新的成绩
	public int add(Result result) {
		String sql = "insert into result (exam_date,score,st_id,sb_id) values(str_to_date(?,'%Y-%m-%d'),?,?,?)";
		Object[] args = { result.getExam_date(), result.getScore(),
				result.getSt_id(), result.getSb_id() };
		int re = ResultUtil.executeUpdate(sql, args);
		return re;
	}

	/**
	 * 修改成绩，根据主键id
	 */

	public int update(Result r) {
		String sql = "UPDATE result SET score=score+5 WHERE id=?";
		Object[] od = { r.getId() };
		int jieguo = ResultUtil.executeUpdate(sql, od);
		return jieguo;

	}

	/**
	 * s删除成绩;
	 */
	public int del(Result r) {
		String sql = "DELETE FROM result WHERE id=?";
		Object[] o = { r.getId() };
		int jieguo = ResultUtil.executeUpdate(sql, o);
		return jieguo;

	}

	/**
	 * 根据分页条件返回集合数据
	 */
	public List<Result> serch(int pageno, int pagesize) {
		String sql = "select * from result limit ?,?";
		int start = (pageno - 1) * pagesize;
		Object[] o = { start, pagesize };
		List<Result> jieguo = ResultUtil.search(sql, o);
		return jieguo;

	}
}
